<?php
/**
 * 两个进程同时间写数据
 */
use Swoole\Table;
use Swoole\Process;


// 在主进程中创建一个内存
$table = new Table(1024);
$table->column('pc_id',Table::TYPE_INT);
$table->column('value',Table::TYPE_INT);
$table->create();

$process1 = new Process(function ($worker) use($table){
    for ($i=0; $i < 100; $i++) { 
        $table->set("p1-{$i}",['pc_id'=> 1, 'value'=>$i]);
    }
}, true);

$process2 = new Process(function ($worker) use($table){
    for ($i=0; $i < 100; $i++) { 
        $table->set("p2-{$i}",['pc_id'=> 2, 'value'=>$i]);
    }
}, true);

$process1->start();
$process2->start();
sleep(1);
foreach ($table as $v) {
    echo  "process={$v['pc_id']} value={$v['value']}" . PHP_EOL;
}